package InsFilter;

import InsLoginRegister.managerBean;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "RegisterFilter",urlPatterns ="/insregisterFilter",servletNames = "RegisterServlet")
public class RegisterFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request =(HttpServletRequest) req;
        HttpServletResponse response =(HttpServletResponse)resp;
        managerBean mb =(managerBean)request.getSession().getAttribute("mb");
        String PNO = mb.getPNO();
        if(PNO.equals("123456")) //当前登陆者为人事部门编号才能添加员工
        {
          chain.doFilter(request,response);
        }
        else
        {
            response.getWriter().write("您不能添加员工！");
            response.sendRedirect("localhost:8084/html/index.jsp");
        }
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
